edwh-editorjs 2.3.2__py3-none-any.whl → 2.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
editorjs/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2.3.2"
1
+ __version__ = "2.4.0"
editorjs/blocks.py CHANGED
@@ -406,7 +406,20 @@ class ImageBlock(EditorJSBlock):
406
406
  def to_markdown(cls, data: EditorChildData) -> str:
407
407
  url = data.get("url", "") or data.get("file", {}).get("url", "")
408
408
  caption = data.get("caption", "")
409
- return f"""![{caption}]({url} "{caption}")\n\n"""
409
+
410
+ with_border = "1" if data.get("withBorder") else ""
411
+ with_background = "1" if data.get("withBackground") else ""
412
+ stretched = "1" if data.get("stretched") else ""
413
+
414
+ if any((with_border, with_background, stretched)):
415
+ # custom type to support custom options:
416
+ return f"""<editorjs type="image" caption="{caption}" border="{with_border}" background="{with_background}" stretched="{stretched}" url="{url}" />\n\n"""
417
+ else:
418
+ return f"""![{caption}]({url} "{caption}")\n\n"""
419
+
420
+ @classmethod
421
+ def _caption(cls, node: MDChildNode):
422
+ return node.get("alt") or node.get("caption") or ""
410
423
 
411
424
  @classmethod
412
425
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -414,15 +427,34 @@ class ImageBlock(EditorJSBlock):
414
427
  {
415
428
  "type": "image",
416
429
  "data": {
417
- "caption": cls.to_text(node),
418
430
  "file": {"url": node.get("url")},
431
+ "caption": cls._caption(node),
432
+ "withBorder": bool(node.get("border", False)),
433
+ "stretched": bool(node.get("stretched", False)),
434
+ "withBackground": bool(node.get("background", False)),
419
435
  },
420
436
  }
421
437
  ]
422
438
 
423
439
  @classmethod
424
440
  def to_text(cls, node: MDChildNode) -> str:
425
- return node.get("alt") or node.get("caption") or ""
441
+ caption = cls._caption(node)
442
+ url = node.get("url")
443
+
444
+ background = node.get("background") or ""
445
+ stretched = node.get("stretched") or ""
446
+ border = node.get("border") or ""
447
+
448
+ return f"""
449
+ <div class="ce-block {stretched and 'ce-block--stretched'}">
450
+ <div class="ce-block__content">
451
+ <div class="cdx-block image-tool image-tool--filled {background and 'image-tool--withBackground'} {stretched and 'image-tool--stretched'} {border and 'image-tool--withBorder'}">
452
+ <div class="image-tool__image">
453
+ <img class="image-tool__image-picture" src="{url}" title="{caption}" alt="{caption}">
454
+ </div>
455
+ </div>
456
+ </div>
457
+ """
426
458
 
427
459
 
428
460
  @block("blockquote", "quote")
editorjs/core.py CHANGED
@@ -1,11 +1,13 @@
1
1
  import json
2
2
  import typing as t
3
+ import warnings
3
4
 
4
5
  import markdown2
5
6
  import mdast
6
7
  from typing_extensions import Self
7
8
 
8
9
  from .blocks import BLOCKS
10
+ from .exceptions import TODO
9
11
  from .helpers import unix_timestamp
10
12
  from .types import MDRootNode
11
13
 
@@ -41,13 +43,26 @@ class EditorJS:
41
43
  for child in blocks:
42
44
  _type = child["type"]
43
45
  if not (block := BLOCKS.get(_type)):
44
- raise TypeError(f"from_json: Unsupported block type `{_type}`")
45
-
46
- data = child.get("data", {})
47
- # forward any 'tunes' via data:
48
- data["tunes"] = data.get("tunes") or child.get("tunes") or {}
49
-
50
- markdown_items.append(block.to_markdown(data))
46
+ warnings.warn(
47
+ f"from_json: Unsupported block type `{_type}`",
48
+ category=RuntimeWarning,
49
+ )
50
+ continue
51
+
52
+ try:
53
+ data = child.get("data", {})
54
+ # forward any 'tunes' via data:
55
+ data["tunes"] = data.get("tunes") or child.get("tunes") or {}
56
+
57
+ markdown_items.append(block.to_markdown(data))
58
+ except Exception as e:
59
+ warnings.warn(
60
+ "from_json: Oh oh, unexpected block failure!",
61
+ category=RuntimeWarning,
62
+ source=e,
63
+ )
64
+ # if isinstance(e, TODO):
65
+ # raise e
51
66
 
52
67
  markdown = "".join(markdown_items)
53
68
  return cls.from_markdown(markdown)
@@ -76,9 +91,22 @@ class EditorJS:
76
91
  for child in self._mdast["children"]:
77
92
  _type = child["type"]
78
93
  if not (block := BLOCKS.get(_type)):
79
- raise TypeError(f"to_json: Unsupported block type `{_type}`")
80
-
81
- blocks.extend(block.to_json(child))
94
+ warnings.warn(
95
+ f"to_json: Unsupported block type `{_type}`",
96
+ category=RuntimeWarning,
97
+ )
98
+ continue
99
+
100
+ try:
101
+ blocks.extend(block.to_json(child))
102
+ except Exception as e:
103
+ warnings.warn(
104
+ "to_json: Oh oh, unexpected block failure!",
105
+ category=RuntimeWarning,
106
+ source=e,
107
+ )
108
+ # if isinstance(e, TODO):
109
+ # raise e
82
110
 
83
111
  data = {"time": unix_timestamp(), "blocks": blocks, "version": EDITORJS_VERSION}
84
112
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edwh-editorjs
3
- Version: 2.3.2
3
+ Version: 2.4.0
4
4
  Summary: EditorJS.py
5
5
  Project-URL: Homepage, https://github.com/educationwarehouse/edwh-EditorJS
6
6
  Author-email: SKevo <skevo.cw@gmail.com>, Robin van der Noord <robin.vdn@educationwarehouse.nl>
@@ -0,0 +1,10 @@
1
+ editorjs/__about__.py,sha256=yLaFvd-K80rs_ClRVYULStijkok4RfYSaanIt_E-aKM,22
2
+ editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
+ editorjs/blocks.py,sha256=QDUJ55UmDDZxZOxkigGHZ-JC7CP_sDH94Y_z-PRVXf8,28648
4
+ editorjs/core.py,sha256=ra1LADSPiZpbzeAZaVzsJ8aGc3m3xYUO4bpyQLPV3h0,4576
5
+ editorjs/exceptions.py,sha256=oKuWqi4CSnFGZfVZWtTZ2XZeHXm5xF-nAtX_1YLm6sI,230
6
+ editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
7
+ editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
8
+ edwh_editorjs-2.4.0.dist-info/METADATA,sha256=Jwtr4YkhOPCssoqI4pLpvl7kpvHMFgpU74tHPQyG7Gc,996
9
+ edwh_editorjs-2.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ edwh_editorjs-2.4.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- editorjs/__about__.py,sha256=J4CRnpR3v72FGOMp8gqSua_XWZpAfXuqgVWiQFB-gTY,22
2
- editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
- editorjs/blocks.py,sha256=dT54-wCL4sm9fO7OiJO8Q0SgTuHq3wtv7KQiOF81oks,27138
4
- editorjs/core.py,sha256=WSBmAIKwSqHIP_NFmUVUJiyHPgq7D8902Jm9HRf1nSk,3669
5
- editorjs/exceptions.py,sha256=oKuWqi4CSnFGZfVZWtTZ2XZeHXm5xF-nAtX_1YLm6sI,230
6
- editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
7
- editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
8
- edwh_editorjs-2.3.2.dist-info/METADATA,sha256=798OipvvgiexYoOa7x3KFac2MouJVMYQA5KzF6bR1ss,996
9
- edwh_editorjs-2.3.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- edwh_editorjs-2.3.2.dist-info/RECORD,,